#pragma once
#include<iostream>
using namespace std;

namespace egoist
{
	template<class T>
	struct list_Node
	{
		list_Node<T>* _prev;
		list_Node<T>* _next;
		T _data;

		list_Node(const T& x = T())
			:_prev(nullptr)
			,_next(nullptr)
			,_data(x)
		{}
	};

	template<class T>
	struct list_iterator
	{
		typedef list_Node<T> Node;

		Node* _node;

		list_iterator(Node* node)
			:_node(node)
		{}

		T& operator*()
		{
			return _node->_data;
		}

		list_iterator<T>& operator++()
		{
			_node = _node->_next;
			return *this;
		}

		bool operator!=(const list_iterator& lt)
		{
			return _node != lt._node;
		}

	};

	template<class T>
	class list
	{
		typedef list_Node<T> Node;
	public:
		typedef list_iterator<T> iterator;

		list()
		{
			_head = new Node;
			_head->_prev = _head;
			_head->_next = _head;
		}

		iterator begin()
		{
			iterator it(_head->_next);
			return it;
		}

		iterator end()
		{
			return iterator(_head);
		}

		void push_back(const T& x)
		{
			Node* newnode = new Node(x);

			Node* tail = _head->_prev;
			tail->_next = newnode;
			newnode->_prev = tail;
			newnode->_next = _head;
			_head->_prev = newnode;
		}

	private:
		Node* _head;
	};
}